package com.banzhi.shop.activity;

import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.banzhi.shop.R;
import com.banzhi.shop.base.BaseActivity;
import com.banzhi.shop.entity.AboutBanzhi.Banzhi_Data;
import com.banzhi.shop.model.CallBack.AboutBanzhiCallBack;
import com.banzhi.shop.model.IAboutBanzhiModel;
import com.banzhi.shop.model.Impl.AboutBanzhiImpl;
import com.banzhi.shop.utils.ASUtils;
import com.banzhi.shop.utils.LoadingDialogUtils;
import com.banzhi.shop.utils.NoTokenUtils;
import com.banzhi.shop.utils.ToastUtils;
import com.banzhi.shop.utils.Translucent;

import org.json.JSONObject;

/**
 * 关于半职
 */
public class AboutBanzhiActivity extends BaseActivity implements View.OnClickListener, AboutBanzhiCallBack {
    /**
     * 退出
     */
    private ImageView ivback;
    private TextView tvcode;
    private TextView tvtext;
//    private TextView tvphone;
    private IAboutBanzhiModel model;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about_banzhi);
        Translucent.setTranslucent(this);
        setinits();
        setListeners();
        model = new AboutBanzhiImpl();
        LoadingDialogUtils.showProgress(this, "正在加载,请稍后~");
        model.getData(this);
        showViews();
    }

    private void showViews() {
        tvcode.setText(ASUtils.getVersionName(this));
    }

    private void setinits() {
        ivback = (ImageView) findViewById(R.id.iv_back);
        tvcode = (TextView) findViewById(R.id.tv_code);
        tvtext = (TextView) findViewById(R.id.tv_text);
//        tvphone = (TextView) findViewById(R.id.tv_phone);
    }

    private void setListeners() {
        ivback.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }

    /**
     * @param object 获取信息成功
     */
    @Override
    public void ongetDataSuccess(Object object) {
        Banzhi_Data data = (Banzhi_Data) object;

        tvtext.setText(Html.fromHtml(data.getDescription()));
//        tvphone.setText(data.getPhone());
    }

    /**
     * @param object 失败
     */
    @Override
    public void ongetDataError(Object object) {
        JSONObject jsonObject = (JSONObject) object;
        NoTokenUtils.loginOut(this, jsonObject);
        ToastUtils.makeToastShort(jsonObject.optString("msg"));

    }

}
